/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utn.tsb.tej.world_logic;

import java.io.Serializable;
import csm.uttils.generics.Roster;

/**
 *
 * @author Administrador
 */
public class ObjectiveCard implements Comparable, Serializable {

    private int number;
    private Roster<Objective> objectives;

    public ObjectiveCard(int number, Roster objectives) {
        this.objectives = objectives;
        this.number = number;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public ObjectiveCard() {
        objectives = new Roster<Objective>();
    }

    public Roster getObjectives() {
        return objectives;
    }

    public Roster getObjectives(Roster<Player> players, Player player) {
        if (objectives.getFirst() instanceof ObjectiveEliminate) {
            ObjectiveEliminate objective = (ObjectiveEliminate) objectives.getFirst();
            if (!objective.targetExist(players, player)) {
                int nextPlayerIndex;
                if (players.count()-1 == players.indexOf(player)) {
                    nextPlayerIndex = 0;
                } else {
                    nextPlayerIndex = players.indexOf(player) + 1;
                }
                Color newColor = players.getElementInPosition(nextPlayerIndex).getColor();
                objective.setColor(newColor);
            }
            objectives.clear();
            objectives.addFirst(objective);
        }
        return objectives;
    }

    public void setObjectives(Roster objectives) {
        this.objectives = objectives;
    }

    @Override
    public int compareTo(Object o) {
        ObjectiveCard oc = (ObjectiveCard) o;
        return this.number - oc.getNumber();
    }

    public String toString() {
        String aux = number + "\n";
        for (int i = 0; i < objectives.count(); i++) {

            aux += "\t" + objectives.getElementInPosition(i).toString() + "\n";
        }
        return aux;
    }
}
